package com.example.demo.controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

public class TianYou {

	public static String[] YIWEI = { "143052", "514320", "205431", "051243", "320514", "432105" };
	public final static int[] a0 = { 8, 0, 2, 6, 4, 5, 7, 9, 1, 3 };
	public final static int[] a1 = { 3, 4, 8, 0, 2, 6, 1, 5, 7, 9 };
	public final static int[] a2 = { 2, 5, 9, 7, 3, 0, 6, 4, 8, 1 };
	public final static int[] a3 = { 9, 1, 0, 4, 7, 2, 5, 3, 6, 8 };
	public final static int[] a4 = { 6, 8, 1, 5, 0, 3, 4, 7, 9, 2 };
	public final static int[] a5 = { 7, 2, 3, 9, 5, 1, 8, 0, 4, 6 };
	public final static int[] a6 = { 4, 3, 7, 2, 6, 8, 9, 1, 5, 0 };
	public final static int[] a7 = { 1, 6, 4, 3, 9, 7, 2, 8, 0, 5 };
	public final static int[] a8 = { 0, 9, 5, 1, 8, 4, 3, 6, 2, 7 };
	public final static int[] a9 = { 5, 7, 6, 8, 1, 9, 0, 2, 3, 4 };

	public final static int[][] as = { a0, a1, a2, a3, a4, a5, a6, a7, a8, a9 };

	public static void main(String[] args) {
//		Date date = new Date();
		SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm");

		Date date = null;
		try {
			date = formatter.parse("2021-11-04 17:01");
		} catch (ParseException e) {
			e.printStackTrace();
		}
		int nianYue = Integer.parseInt(reqDateNianYue(date));
		int shiFen = Integer.parseInt(reqDateShifen(date));
		System.out.println("年月 === " + nianYue + "时分  = " + shiFen);
		int sum = nianYue + shiFen;
		System.out.println("和 === " + sum);
		// 管理员密码
		int pwd = Integer.parseInt("123456");
		String pwdYiwei = yiwei(pwd + "", pwd % 6);
		
		
		// 移动位置
		String yiweiStr = yiwei(sum + "", sum % 6);
		System.out.println("移动顺序后" + yiweiStr);
		// 置换表
		String getPwd = zhihuan(yiweiStr, pwdYiwei);
		System.out.println("最后的密码" + getPwd);
	}

	public static String reqDateNianYue(Date date) {
		return new SimpleDateFormat("yyyyMM").format(date);
	}

	public static String reqDateShifen(Date date) {
		return new SimpleDateFormat("ddHHmm").format(date);
	}

	public static String zhihuan(String yiweiStr, String pwd) {
		StringBuilder sb = new StringBuilder();
		for (int i = 0; i < yiweiStr.length(); i++) {
			int zong = Integer.parseInt(yiweiStr.charAt(i) + "");
			int heng = Integer.parseInt(pwd.charAt(i) + "");
			sb.append(as[heng][zong]);
		}
		return sb.toString();
	}

	public static String yiwei(String params, int bizType) {

		String key = YIWEI[bizType];
		StringBuilder sb = new StringBuilder("123456");
		for (int i = 0; i < key.length(); i++) {
			int shunxu = Integer.parseInt(key.charAt(i) + "");

			sb.replace(shunxu, shunxu + 1, params.charAt(i) + "");
		}

		return sb.toString();
	}
}
